package kingone.phone_store_spring_practice.controller;

import kingone.phone_store_spring_practice.service.PhoneService;
import kingone.phone_store_spring_practice.util.ResultVOUtil;
import kingone.phone_store_spring_practice.vo.DataVO;
import kingone.phone_store_spring_practice.vo.ResultVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

//@CrossOrigin //用于完成跨域访问
@RestController
@RequestMapping("/phone")
public class PhoneHandler {
    
    @Autowired
    private PhoneService phoneService;

    @GetMapping("/index")
    public ResultVO index(){
        DataVO dataVO = phoneService.findDataVO();
        return ResultVOUtil.success(dataVO);
    }
    
    @GetMapping("/findByCategoryType/{categoryType}")
    public ResultVO findByCategoryType(@PathVariable("categoryType") Integer categoryType){
        return ResultVOUtil.success(phoneService.findPhoneInfoVOByCategoryType(categoryType));
    }
    
    @GetMapping("/findByPhoneId/{phoneId}")
    public ResultVO findByPhoneId(@PathVariable("phoneId") Integer phoneId){
        return ResultVOUtil.success(phoneService.findSpecsPackageVOByPhoneId(phoneId));
    }
}
